import request from "./httpUtils";


export default {
    post(url, data ) {
        const urlPath = this.api[url];
        const token =  sessionStorage.getItem("token") || "";
        const header = {
            Authorization: "Bearer " + token,
        };
        return new Promise((resolve, reject) => {
            request({
                url: urlPath,
                method: "post",
                headers: header,
                data,
            }).then(res => {
                if (res.status == "0") {
                    resolve(res);
                } else {
                    if(res.status != '1022'){
                        // message.warning(res.message);
                    }
                    reject(res);
                }
            }).catch( (error)  => {
                if(error.response.status === 403){
                    // message.warning({content:"登录超时，请重新登录",key:'timeout'});
                }else if(error.response.status === 500){
                    localStorage.removeItem('token');
                    // message.warning({content:"登录超时，请重新登录",key:'timeout'});
                }else{
                    // message.warning({content:"请求错误",key:'error'});
                }
            });
        })
    },
    api: {
        '大屏': "/getBigScreenStatistics.do",
        '实时风险': "/getNewRisks.do",
		'企业详情': "/getFirmDetail.do",
        '企业详情-端口资产列表': "/getAssetPortListFromFirmDetail.do",
        '企业详情-网站测绘列表': "/getAssetAppListFromFirmDetail.do",
        '企业详情-漏洞列表': "/getVulnListFromFirmDetail.do",
    }
};